//
//  SettingMasterViewController.m
//  宜居HD
//
//  Created by 陈柏兵 on 16/5/3.
//  Copyright © 2016年 张金国. All rights reserved.
//

#pragma mark - Getters

#import "SettingMasterViewController.h"
//#import "MasterTableCell.h"
#import "Macro.h"
#import "Masonry.h"

@interface SettingMasterViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *masterTable;
@property (nonatomic, strong)NSArray *titleArray;
@end

static NSString *masterIdentifier = @"masterCell";

@implementation SettingMasterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleArray];
    [self layoutUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Private
/**
 *  布局大块view
 */
- (void)layoutUI {
    [self.masterTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.width.equalTo(self.view.mas_width);
        make.height.equalTo(self.view.mas_height);
    }];
}


#pragma mark - UITableView Delegate

//section头部高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return SCREEN_HEIGHT*0.26;
}
//section头部试图View
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIImageView *headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"headerView"]];
    headerImageView.contentMode = UIViewContentModeScaleAspectFit;
    headerImageView.clipsToBounds = YES;
    return headerImageView;
}

//sectiond底部高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return SCREEN_HEIGHT*0.26;
}
//section底部试图View
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIImageView *footerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"footerView"]];
    footerImageView.contentMode = UIViewContentModeScaleAspectFit;
    return footerImageView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _titleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:masterIdentifier];
    if (cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:masterIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor = [UIColor colorWithRed:0.788 green:0.804 blue:0.882 alpha:1.000];
    cell.textLabel.text = _titleArray[indexPath.row];
    
    NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
    [self tableView:_masterTable didSelectRowAtIndexPath:index];
    
    return cell;
}

#pragma mark - Event Response

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger type = indexPath.row;
    NSString *controllerName;
    
    switch (type) {
        case 0:
             controllerName = @"SettingDetailFunctionViewController";
            break;
            
        case 1:
            controllerName = @"SettingDetailHelpViewController";
           break;
            
        case 2:
            controllerName = @"SettingDetailFeedBackViewController";
            break;
            
        case 3:
            controllerName = @"SettingDetailSandTableViewController";
            break;
            
        case 4:
            controllerName = @"SettingDetailMessageViewController";
            break;
            
        case 5:
            controllerName = @"SettingDetailAboutViewController";
            break;
            
        default:
            break;
    }
    
    
    
    if (self.block != nil) {
        self.block(controllerName);
    }
}


- (NSArray *)titleArray {
    if (_titleArray == nil) {
        _titleArray = @[@"功能介绍",@"使用帮助",@"意见反馈",@"沙盘设置",@"消息通知",@"关于宜居"];
    }
    return _titleArray;
}

- (UITableView *)masterTable
{
    if (_masterTable == nil) {
        _masterTable = [[UITableView alloc] init];
        _masterTable.backgroundColor = [UIColor colorWithRed:211/255.0 green:215/255.0 blue:230/255.0 alpha:1.000];
        _masterTable.rowHeight = self.view.frame.size.height * 0.08;
        [_masterTable registerClass:[UITableViewCell class] forCellReuseIdentifier:masterIdentifier];
        _masterTable.backgroundColor = [UIColor colorWithRed:0.788 green:0.804 blue:0.882 alpha:1.000];
        _masterTable.scrollEnabled = NO;
        _masterTable.dataSource = self;
        _masterTable.delegate = self;
        _masterTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_masterTable];
    }
    return _masterTable;
}


@end
